# resources.rb
# created by: Dan Alexander
# date: 3/5/2011
# license: New BSD License
#
# Resource manager for the client. It loads all of the
# resources (images, sound, etc), which can then be
# accessed by calling the current functions.

include Rubygame

class ResourceManager

	#the constructor. pass in a file to be used as a tileset,
	#along with width and height of each tile
	def initialize(file)
		main_dir = File.dirname(__FILE__)
		
		@images = Hash.new
	
		aFile = File.new(file)
		aFile.each_line do |line|
			#basically, add a "comment" ability to the resource file
			if line.start_with?("#") == false 
				key = line.split(',')[0]
				
				line2 = line.strip!
				if line2 == nil
					line2 = line
				end
				fil = File.join( main_dir, line2.split(',')[1])
				if (File.exists?(fil) == true)
					if $debug == true then p "loading file: " + fil end
					img = Surface.load fil
					@images[key] = img
				else
					if $debug == true then p "could not load file: " + fil end
				end
			end
		end
	end
	
	
	def get_tile(key)
		@images[key]
	end
end